<template>
  <div class="body">
    <div class="title">故障报修标题</div>
    <div class="inquire">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="楼栋ID">
          <el-select
            v-model="formInline.region"
            placeholder="请选择"
            class="id"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input
            v-model="formInline.user"
            placeholder="居民姓名"
            class="name"
          ></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input
            v-model="formInline.user"
            placeholder="居民电话"
            class="phone"
          ></el-input>
        </el-form-item>
        <el-form-item label="房间号">
          <el-input
            v-model="formInline.user"
            placeholder="房间号"
            class="room"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-form-item label="住户类型">
            <el-select
              v-model="formInline.region"
              placeholder="请选择"
              class="type"
            >
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="fun">
      <el-button type="danger" @click="deleteall">批量删除</el-button>
    </div>
    <el-table
      border
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40"></el-table-column>

      <el-table-column prop="id" label="id" width="70"> </el-table-column>
      <el-table-column prop="typename" label="故障类型" width="110"> </el-table-column>
      <el-table-column prop="address" label="维修地址" width="120"> </el-table-column>
      <el-table-column prop="images.url" label="故障图片" width="120">
      </el-table-column>
      <el-table-column prop="content" label="故障描述" width="200"> </el-table-column>
      <el-table-column prop="statename" label="维修状态" width="90"> </el-table-column>
      <el-table-column prop="username" label="业主名称" width="120">
      </el-table-column>
      <el-table-column
        prop="addtime"
        label="维修日期"
        show-overflow-tooltip
        width="200"
      >
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip style="width: 10%"  >
        <template slot-scope="scope">
          <el-button type="success">修改</el-button>
        <el-button type="danger" @click="delrow(scope.row.id)">删除</el-button>
        </template>
        
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="Inline.page"
        :page-sizes="[1, 2, 5]"
        :page-size="Inline.psize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="counts"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import http from "../../utils/request";
import {repairsDeleteall,repairslist} from '../../api/user'
export default {
  data() {
    return {
      alldelete:'',
      Inline: {
        psize: 1,
        page: 1,
      },
      formInline:{
        user:'',
        region:'',

      },
      counts: 0,

      tableData: [],
      multipleSelection: [],
      
    };
  },
  mounted() {
    this.searchlist();
  },
  methods: {
     delrow(id) {
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(()=>{
        
          http.get('/api/repairs/delete?id='+id).then(res=>{
            if(res.errCode===10000){
             this.$message({
            type: "success",
            message: "删除成功!",
           
          }); 
           this.searchlist()
          }
          })
          
      }).catch(()=>{
          this.$message({
            type: "info",
            message: "已取消删除",
          });
      })
    },   
    async searchlist() {
      let res = await repairslist({
        pageCounts:this.Inline.page,
        pageSize:this.Inline.psize
      })
      console.log(res);
      this.tableData=res.data.list
      this.page=res.data.pageCounts
      this.psize=res.data.pageSize
      this.counts=res.data.counts
      console.log(this.counts);

    },
    onSubmit() {
      console.log("submit!");
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    handleSelectionChange(val) {
      this.alldelete = val;
      // console.log(val);
    },
    async deleteall(){
      let self = this
      if(this.alldelete.length==0){
         this.$message({
            type: "warning",
            message: "请选者删除人!",
           
          }); 
      }else{
        let ids = []
        self.alldelete.forEach((item)=>{
          ids.push(item.id)
        })
        let res = await repairsDeleteall({
          ids:ids
        });
        console.log(res);
        if(res.errCode===10000){
          this.$message({
            message:'删除成功',
            type:'success'
          })
        }
        this.searchlist()
      }
    },
    handleSizeChange(val) {
      this.Inline.psize = val;
      // this.page=1
      this.searchlist();
    },
    handleCurrentChange(val) {
      this.Inline.page = val;
      this.searchlist();
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
   
  },
};
</script>

<style lang="less" scoped>
.title {
  color: rgb(77, 119, 196);
  border-bottom: 1px solid #eeeeee;
  padding-bottom: 30px;
  margin-bottom: 30px;
}
.demo-form-inline {
  padding-left: 20px;
}
.id {
  width: 250px;
}
.name {
  width: 150px;
}
.phone {
  width: 225px;
}
.room {
  width: 150px;
}
.type {
  width: 160px;
}
.fun {
  padding-left: 20px;
  margin-bottom: 20px;
}
.el-table {
  margin-left: 20px;
  margin-right: 20px;
}
.block {
  text-align: center;
}
.left {
  padding-left: 10px;
  box-sizing: border-box;
  width: 50%;
}
.el-form {
  display: flex;
}
.photo {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  p {
    margin-left: 30px;
    margin-right: 50px;
  }
}
.avatar-uploader {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 80px;
  height: 80px;
}
.avatar-uploader:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>